/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.meanzoft.minecraft_clone.map;

import org.meanzoft.minecraft_clone.block2.Block;
import org.meanzoft.minecraft_clone.block2.BlockGrass;
import org.meanzoft.minecraft_clone.block2.BlockHighGrass;
import org.meanzoft.minecraft_clone.block2.BlockLeaves;
import org.meanzoft.minecraft_clone.block2.BlockStone;
import org.meanzoft.minecraft_clone.block2.BlockPlanks;
import org.meanzoft.minecraft_clone.block2.BlockWood;
import org.meanzoft.minecraft_clone.world.WorldManager;

/**
 *
 * @author Meanz
 */
public class Map {

    public static final int BLOCK_STONE = 1;
    public static final int BLOCK_GRASS = 2;
    public static final int BLOCK_PLANKS = 3;
    public static final int BLOCK_LIGHT = 4;
    public static final int BLOCK_HIGHGRASS = 5;
    public static final int BLOCK_WOOD = 6;
    public static final int BLOCK_LEAVES = 7;

    public Map() {
        build();
    }

    public void build() {

        for (int x = 0; x < 50; x++) {
            for (int z = 0; z < 50; z++) {
                addBlock(x, 0, z, BLOCK_GRASS);
            }
        }

        for (int x = 0; x < 50; x++) {
            for (int y = 1; y < 2; y++) {
                addBlock(x, y, 0, BLOCK_STONE);
            }
        }

        for (int x = 0; x < 50; x++) {
            for (int y = 1; y < 2; y++) {
                addBlock(x, y, 50, BLOCK_STONE);
            }
        }

        for (int z = 0; z < 50; z++) {
            for (int y = 1; y < 2; y++) {
                addBlock(0, y, z, BLOCK_STONE);
            }
        }

        for (int z = 0; z < 50; z++) {
            for (int y = 1; y < 2; y++) {
                addBlock(50, y, z, BLOCK_STONE);
            }
        }

        for (int x = 30; x < 40; x++) {
            for (int y = 1; y < 5; y++) {
                addBlock(x, y, 10, BLOCK_PLANKS);
            }
        }

        for (int x = 30; x < 40; x++) {
            for (int y = 1; y < 5; y++) {
                addBlock(x, y, 15, BLOCK_PLANKS);
            }
        }

        for (int z = 10; z < 15; z++) {
            for (int y = 1; y < 5; y++) {
                addBlock(30, y, z, BLOCK_PLANKS);
            }
        }

        for (int z = 10; z < 16; z++) {
            for (int y = 1; y < 5; y++) {
                addBlock(40, y, z, BLOCK_PLANKS);
            }
        }

        for (int z = 10; z < 16; z++) {
            for (int x = 30; x < 40; x++) {
                addBlock(x, 5, z, BLOCK_PLANKS);
            }
        }

        createTree(11, 1, 10);
        addBlock(10, 1, 10, BLOCK_HIGHGRASS);
        addBlock(11, 1, 9, BLOCK_HIGHGRASS);
        createTree(20, 1, 32);
        addBlock(19, 1, 32, BLOCK_HIGHGRASS);
        addBlock(20, 1, 31, BLOCK_HIGHGRASS);   
        createTree(36, 1, 42);
        createTree(42, 1, 25);
        addBlock(32, 1, 31, BLOCK_HIGHGRASS);
        addBlock(38, 1, 25, BLOCK_HIGHGRASS);
        addBlock(31, 1, 41, BLOCK_HIGHGRASS);
        addBlock(25, 1, 39, BLOCK_HIGHGRASS);
        addBlock(42, 1, 29, BLOCK_HIGHGRASS);
        
        
        addBlock(7, 1, 5, BLOCK_HIGHGRASS);
        addBlock(3, 1, 3, BLOCK_WOOD);
        removeBlock(30, 1, 12);
        removeBlock(30, 2, 12);
        
        for(int x=50; x < 128; x++) {
            for(int y=0; y < 128; y++) {
                for(int z=0; z < 128; z++) {
                    addBlock(x, y, z, BLOCK_STONE);
                }
            }
        }

    }

    public void removeBlock(int x, int y, int z) {
        WorldManager.getWorld().removeBlock(x, y, z);
    }

    public void addBlock(int x, int y, int z, int block_type) {
        Block b = null;
        b = new BlockGrass();
        switch (block_type) {
            case BLOCK_STONE:
                b = new BlockStone();
                break;

            case BLOCK_GRASS:
                b = new BlockGrass();
                break;

            case BLOCK_PLANKS:
                b = new BlockPlanks();
                break;

            case BLOCK_HIGHGRASS:
                b = new BlockHighGrass();
                break;
             
            case BLOCK_WOOD:
                b = new BlockWood();
                break;

            case BLOCK_LEAVES:
                b = new BlockLeaves();
                break;

            default:
                b = new BlockGrass();
                break;
        }
        WorldManager.getWorld().addBlock(x, y, z, b);
    }

    public void createTree(int x, int y, int z) {

        for (int stubPiece = 0; stubPiece < 4; stubPiece++) {
            addBlock(x, y + stubPiece, z, BLOCK_WOOD);
        }

        for (int _y = 0; _y < 3; _y++) {
            for (int _x = -1; _x < 2; _x++) {
                for (int _z = -1; _z < 2; _z++) {
                    addBlock(x + _x, 4 + _y, z + _z, BLOCK_LEAVES);
                }
            }
        }

    }
}
